/**
 * 数据库连接
 */
const mysql = require('mysql')

let connection = mysql.createConnection({
  host: '101.201.117.111', //本机
  user: 'bzaq', //账号root
  password: '123456', //密码12345
  database: 'bzaq_dev', //数据库名
  port: '3306'
})

connection.connect()

connection.query(
  'select id,name,num,password,department_code from staff where id < 10',
  function(error, results, fields) {
    if (error) throw error //抛出异常阻止代码往下执行
    // 没有异常打印输出结果
    results.forEach(item => {
      // console.log(item.id, item.name)
      console.log(
        item.id,
        item.name,
        item.num,
        item.password,
        item.department_code
      )
    })
  }
)

connection.end()
